package middlewere

import (
	"Gin/global/pkg"
	"encoding/json"
	"github.com/gin-gonic/gin"
	"net/http"
)

func VipMiddlewere() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.Request.Header.Get("token")
		data, _ := pkg.TokenData(token)
		vip := data["vip"].(float64)
		if vip < 2 {
			c.AbortWithStatusJSON(http.StatusOK, gin.H{
				"code": 403,
				"msg":  "非会员",
			})
			return
		}
		set, _ := json.Marshal(int64(vip))
		c.Request.ParseForm()
		c.Request.Form.Set("vip", string(set))
		c.Next()
	}
}
